-- avatar
-- created by panyl
-- 召唤兽：解救的野猪

-- 一次最多可召唤的数量
local MAX_SUMMON_COUNT = 10;

return {
    fetchInitData = function(classId)
        local cycle = SummonM.query(classId, "cycle") or 1;
        local action = DungeonM.getRandSeed("avatar_summon") % cycle + 1;

        return {
            ["attack"] = ME.user:getAttack(),
            ["action"] = CombatM.getRound() + action,       -- 下次行动回合随机
        };
    end,

    doSummon = function(classId, para)
        para = para or {};

        -- 有些格子不能被召唤
        local illegalPos = BossTentM.getCanRefreshPos();

        local curCount = 0;
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);

            if  grid:isOpened() and
                not grid.bonus and not grid.has_key and
                (grid.type == GRID_TYPE_EMPTY or grid.state == GRID_STATE_DISABLE)
                and table.indexOf(illegalPos, pos) < 0 then

                para["pos"] = pos;
                SummonM.apply(classId, para);

                curCount = curCount + 1;

                if curCount >= MAX_SUMMON_COUNT then
                    break;
                end
            end
        end

        return true;
    end,
};
